/** @noSelfInFile **/

import {effectAdapter, IEffectAdapter} from "../../adapter/adapterInterface/model2/IEffectAdapter";
import {LocModel} from "../../base/LocModel";
import {GlobalModel} from "../model1/GlobalModel";
import {HandleModel} from "../model1/HandleModel";

export class EffectModel implements HandleModel {
  effectAdapt: IEffectAdapter;

  public handle: any;
  id: string;
  nikeName: string;

  defaultSize: number = 0;
  bShow: boolean = true;

  constructor(effect: any, name: string) {
    this.nikeName = name;
    this.effectAdapt = effectAdapter.adapter;
    this.bindHandle(effect)
  }

  getHandleId(): string {
    return this.id;
  }

  public set loc(loc: LocModel) {
    this.effectAdapt.setLoc(this.handle, loc);
  }
  public get loc() {
    return this.effectAdapt.getLoc(this.handle);
  }

  public getSize() {
    return this.effectAdapt.getSize(this.handle);
  }
  public setSize(value: number, bAways: boolean = false) {
    if (bAways) {
      this.defaultSize = value;
    }
    this.effectAdapt.setSize(this.handle, value);
  }


  public set angleZ(value: number) {
    this.effectAdapt.setAngleZ(this.handle, value);
  }

  public set angleX(value: number) {
    this.effectAdapt.setAngleX(this.handle, value);
  }

  public set angleY(value: number) {
    this.effectAdapt.setAngleY(this.handle, value);
  }

  public set show(value: boolean) {
    this.bShow = value;
    this.effectAdapt.setShow(this.handle, value, this.defaultSize);
  }

  public get show() {
    return this.bShow
  }


  destroy() {
    this.effectAdapt.destroy(this.handle);
    this.handle = undefined;
  }

  bindHandle(handle: any) {
    this.effectAdapt.bindHandle(handle)
    this.handle = handle;
    this.defaultSize = this.getSize();
    this.id = GlobalModel.getHandleId(this.handle);
  }

  equal(handle: EffectModel): boolean {
    return this.effectAdapt.equal(this.handle, handle.handle);
  }

  isValid(): boolean {
    return this.effectAdapt.isValid(this.handle);
  }

}
